package details;

import com.ticket.*;

import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
import java.util.Scanner;

public class Concert {
    private static Scanner scanner = new Scanner(System.in);

    public static void concert() {
        InputStream resourceAsStream = Concert.class.getClassLoader().getResourceAsStream("jdbc.properties");
        Properties properties = new Properties();

        try {
            properties.load(resourceAsStream);
            String driverClass = properties.getProperty("driverClass");
            String url = properties.getProperty("url");
            String user = properties.getProperty("user");
            String password = properties.getProperty("password");

            Class.forName(driverClass);

            Connection connection = DriverManager.getConnection(url, user, password);
            // 获取数据库操作对象
            Statement statement = connection.createStatement();
            // 执行SQL
            String sql = "select * from concert";
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                Date date = resultSet.getDate("date");
                String address = resultSet.getString("address");
                String price = resultSet.getString("price");
                System.out.println(id + "\t" + name + "\t\t" + date + "\t" + address + "\t" + price);
            }
            while (true) {
                System.out.println("****************************");
                System.out.println("欢迎进入演唱会详情界面！");
                System.out.println("1.查询票务信息");
                System.out.println("2.购票");
                System.out.println("3.客服");
                System.out.println("0.返回");
                System.out.println("-1.退出");
                System.out.println("****************************");

                System.out.print("请输入数字选择对应的功能：");
                String i = scanner.next();
                if (i.equals("1")) { //查询
                    UserSelect.select();
                } else if (i.equals("2")) { //购票
                    BuyTicket.buy();
                } else if (i.equals("3")) { //客服
                    ChatService.Question();
                } else if (i.equals("0")) { //返回
                    UserLogin.index();
                    break;
                } else if (i.equals("-1")) { //退出
                    break;
                } else {
                    System.out.println("请输入正确的数字！");
                }
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
